from django.apps import AppConfig


class GoodsConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'goods'

    def ready(self):
        # 预加载所有秒杀商品的库存
        from .models import SeckillGoods
        seckill_goods_ids = SeckillGoods.objects.values_list('id', flat=True)
        for seckill_goods_id in seckill_goods_ids:
            from utils.redis_utils import preload_stock_to_redis, get_goods_detail
            preload_stock_to_redis(seckill_goods_id)
            get_goods_detail(seckill_goods_id)